import { useI18n } from 'vue-i18n';
import useImageUploader from './upload-image';
import { message } from 'ant-design-vue';
import 'ant-design-vue/es/message/style/css';

export default function useMDEditorImageUploader() {

  const { t } = useI18n();
  const { uploadImage } = useImageUploader(t, 'article-images');

  const handleUploadImage = (event, insertImage, files) => {
    uploadImage({
      file: files[0],
      onSuccess: (resp) => {
        insertImage({
          url: resp.data[0],
          desc: '图片描述'
        })
      },
      onError: (e) => {
        message.error(`上传失败：${e}`)
      }
    })
  }

  return { handleUploadImage };
}